package com.mowh.gof23.behavioral.patterns.command.command;

import java.util.Iterator;
import java.util.Stack;

/**
 * @author mowh1gd
 * @create 2023/10/27 11:06
 */
public class MacroCommand implements Command{
    private Stack commands = new Stack<>();
    @Override
    public void execute() {
        Iterator it = commands.iterator();
        while (it.hasNext()) {
            ((Command)it.next()).execute();
        }
    }
    public void append(Command command) {
        if (command != this) {
            commands.push(command);
        }
    }
    public void undo() {
        if (!commands.empty()) {
            commands.pop();
        }
    }
    public void clear() {
        commands.clear();
    }
}
